package com.lx.tldoj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lx.tldoj.common.ErrorCode;
import com.lx.tldoj.constant.CommonConstant;
import com.lx.tldoj.exception.BusinessException;
import com.lx.tldoj.exception.ThrowUtils;
import com.lx.tldoj.mapper.CompetitionMapper;
import com.lx.tldoj.model.dto.competition.CompetitionQueryRequest;
import com.lx.tldoj.model.entity.Competition;
import com.lx.tldoj.model.entity.User;
import com.lx.tldoj.model.vo.CompetitionVO;
import com.lx.tldoj.model.vo.UserVO;
import com.lx.tldoj.service.CompetitionService;
import com.lx.tldoj.service.UserService;
import com.lx.tldoj.utils.SqlUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @description 针对表【competition(题目)】的数据库操作Service实现
* @createDate 2023-08-07 20:58:00
*/
@Service
public class CompetitionServiceImpl extends ServiceImpl<CompetitionMapper, Competition>
    implements CompetitionService{


    @Resource
    private UserService userService;

    @Override
    public void validCompetition(Competition competition, boolean add) {

    }

    /**
     * 获取查询包装类（用户根据哪些字段查询，根据前端传来的请求对象，得到 mybatis 框架支持的查询 QueryWrapper 类）
     *
     * @param competitionQueryRequest
     * @return
     */
    @Override
    public QueryWrapper<Competition> getQueryWrapper(CompetitionQueryRequest competitionQueryRequest) {
        QueryWrapper<Competition> queryWrapper = new QueryWrapper<>();
        if (competitionQueryRequest == null) {
            return queryWrapper;
        }

        return queryWrapper;
    }

    @Override
    public CompetitionVO getCompetitionVO(Competition competition, HttpServletRequest request) {
        CompetitionVO competitionVO = CompetitionVO.objToVo(competition);

        return competitionVO;
    }

    @Override
    public Page<CompetitionVO> getCompetitionVOPage(Page<Competition> competitionPage, HttpServletRequest request) {
        List<Competition> competitionList = competitionPage.getRecords();
        Page<CompetitionVO> competitionVOPage = new Page<>(competitionPage.getCurrent(), competitionPage.getSize(), competitionPage.getTotal());
        if (CollectionUtils.isEmpty(competitionList)) {
            return competitionVOPage;
        }

        // 填充信息
        List<CompetitionVO> competitionVOList = competitionList.stream().map(competition -> {
            CompetitionVO competitionVO = CompetitionVO.objToVo(competition);

            return competitionVO;
        }).collect(Collectors.toList());
        competitionVOPage.setRecords(competitionVOList);
        return competitionVOPage;
    }


}




